package com.github.service.impl;

import com.github.bean.CallLog;
import com.github.mapper.CallLogMapper;
import com.github.service.CallLogServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CallLogServerImpl implements CallLogServer {
    @Autowired
    private CallLogMapper callLogMapper;

    @Override
    public boolean addCallLog(CallLog callLog) {
        try {
            int flag = callLogMapper.addCallLog(callLog);
            return flag > 0;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public boolean setEndTime(long request_id, long time) {
        try {
            int flag = callLogMapper.setEndTime(request_id, time);
            return flag > 0;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public boolean setMsg(long request_id, String msg, boolean isCover) {
        try {
            String message = getMsg(request_id);
            if (isCover || message == null || message.isEmpty()) {
                int flag = callLogMapper.setMsg(request_id, msg);
                return flag > 0;
            }
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public String getMsg(long request_id) {
        try {
            return callLogMapper.getMsg(request_id);
        } catch (Exception e) {
            return "";
        }
    }

    @Override
    public List<CallLog> getCallLogByAccount(String account) {
        return callLogMapper.getCallLogByAccount(account);
    }

    @Override
    public boolean delCallLogByAccount(String account) {
        int flag = callLogMapper.delCallLogByAccount(account);
        return flag > 0;
    }

    @Override
    public void delCallLog() {
        callLogMapper.delCallLog();
    }
}
